import VXETable from 'vxe-table'
import Price from '../../../components/Price'
import InputNumber from '../../../components/InputNumber'
import { handlePropsMethod } from '../../../utils'

VXETable.renderer.add('Price', {
  autofocus: '.el-input__inner',
  renderEdit(h, renderOpts, params) {
    const { options } = renderOpts
    const { row, column, $table } = params
    const _options = handlePropsMethod(options, params, ['disabled'])

    return [
      <InputNumber
        v-model={row[column.property]}
        onChange={() => {
          $table.updateStatus(params)
        }}
        options={_options}
      />
    ]
  },
  renderCell(h, renderOpts, params) {
    const { row, column } = params

    return [<Price value={row[column.property]} />]
  }
})

/** @type { Column } */
export const options = {
  showOverflow: 'tooltip',
  align: 'right'
}
